Shader "Level4/Displacement"{
	Properties{
		_MainTex("baseMap",2d) = ""{}
		_DisplacementScale("scale",float) = 5
		_DisplacementBias("bias",float) = 0
		_Repeat("repeat",float) = 10
	}
	
	CGINCLUDE
	#include "UnityCG.cginc"
	
	sampler2D _MainTex;
	float _DisplacementScale;
	float _DisplacementBias;
	float _Repeat;
	
	struct v2f{
		float4 pos:POSITION;
		float2 uv:TEXCOORD;
	};
	
	v2f vert(appdata_full data){
		v2f v;
		v.uv = data.texcoord.xy * _Repeat;
		float displacement = tex2Dlod(_MainTex,float4(v.uv,0,0)).r;
		displacement = displacement * _DisplacementScale + _DisplacementBias;
		
		float3 position = data.vertex + data.normal * displacement;
		v.pos = mul(UNITY_MATRIX_MVP,float4(position,1));
		return v;
	}
	
	float4 frag(v2f v):COLOR{
		float4 c = tex2D(_MainTex,v.uv);
		return c;
	}
	
	ENDCG
	
	SubShader{
		
		Pass{
			CGPROGRAM
			#pragma target 3.0
			#pragma glsl
			#pragma vertex vert
			#pragma fragment frag
			
			
			ENDCG
		}
	}
}